﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;

namespace GComp.Apps.EasyStock.DataModel.Common {
    public class SearchQuery : YQLQuery {
        const string OneSymbolQuery = "select * from yahoo.finance.quotes where quote.name LIKE \"{1}\"";

        public SearchQuery(string symbol, string name) {
            _query = string.Format(OneSymbolQuery, symbol, name);
        }

        public async Task<IEnumerable<StockQuote>> GetAnswerAsync() {
            XDocument doc = await GetXmlAnswerAsync();
            List<StockQuote> result = new List<StockQuote>();
            foreach (var quote in doc.Descendants("quote")) {
                result.Add(StockQuote.FromXml(quote));
            }
            return result;
        }

    }
}
